package net.zjitc.action;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;
import net.zjitc.domain.User;
import net.zjitc.service.UserService;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/2/27.
 */
@Controller
@Scope("prototype")
public class UserAction implements ModelDriven<User>{
    /*登录界面
    * */
    private  String username;
    private User model=new User();
    private  String password;
    private  String message;

    /*public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


*/
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
    public String loginUI(){
        return  "loginUI";
    }
    //登录
    @Resource
    private UserService userService;
    public String login(){


        boolean b=userService.findUsernamepassword(model.getUsername(),model.getPassword());
        ActionContext.getContext().getValueStack().push(b);
        if (b){
            message="用户名已经存在";
            return  "addfail";
        }
        message="注册成功";
        List<User> userList=userService.findall();
        ActionContext.getContext().put("userList",userList);
        return  "addsuccess";
    }

    @Override
    public User getModel() {

        return model;
    }
}
        //如果有用户的话，返回登录成功



